package org.dao.imp;

import java.util.List;

import org.dao.KcDao;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.model.Kcb;


public class KcDaoImp implements KcDao {

	public List getAll() {
		try {
		 Session session=org.util.HibernateSessionFactory.getSession();
		 Transaction ts=session.beginTransaction();
		 List list=session.createQuery("from Kcb").list();
		 ts.commit();
		 org.util.HibernateSessionFactory.closeSession();
		 return list;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public Kcb getOneKc(String kch) {
		try {
			Session session=org.util.HibernateSessionFactory.getSession();
			Transaction ts=session.beginTransaction();
			Query query=session.createQuery("from Kcb where kch=?");
			query.setParameter(0, kch);
			query.setMaxResults(1);
			Kcb kc=(Kcb)query.uniqueResult();
			ts.commit();
			session.clear();
			return kc;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

}
